home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume2 / sysinfo < prev    next >
Encoding:
Internet Message Format  |  1991-08-07  |  10.8 KB

  1. From: lenny@icus.UUCP (Lenny Tropiano)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i024: sysinfo: display system info on window (UNIX PC only)
  4. Message-ID: <7138@ncoast.UUCP>
  5. Date: 28 Jan 88 00:36:48 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. Comp.sources.misc: Volume 2, Issue 24
  9. Submitted-By: Lenny Tropiano <lenny@icus.UUCP>
  10. Archive-Name: sysinfo
  11.  
  12. [WARNING!!!  I see a bug in the Makefile.  The "install" commands do chown/
  13. chgrp/chmod on the DIRECTORY, not the file.  Fix it before you use it.  ++bsa]
  14.  
  15. Here's a little ditty I wrote:
  16.  
  17. --- cut here --- --- cut here --- --- cut here --- --- cut here ---
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of shell archive."
  26. # Contents:  README Makefile sysinfo.c
  27. # Wrapped by lenny@icus.UUCP on Sun Jan 24 01:13:20 EST 1988
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f README -a "${1}" != "-c" ; then 
  30.   echo shar: Will not over-write existing file \"README\"
  31. else
  32. echo shar: Extracting \"README\" \(1842 characters\)
  33. sed "s/^X//" >README <<'END_OF_README'
  34. XI wrote this little ditty just to utilize the two lines on the bottom of
  35. Xthe screen where the soft labels for the function keys are normally displayed.
  36. XThis program will only work if you login on the console (obviously) and
  37. Xyou aren't using the "user agent" or something that needs those two lines.
  38. X
  39. XI give thanks to Scott Hazen Mueller for his contribution of "newmgr.c"
  40. Xthat initially gave me the idea for displaying the file system information.
  41. X
  42. XAfter unpacking the shar file, "su" and become root.  Then type:
  43. X
  44. X    # make install
  45. X
  46. XThis will copy the program into /usr/lbin (as defined by the Makefile) but
  47. Xyou might just want to have this for your own "bin" directory, because
  48. Xit is only useful if you run on a windowed device.
  49. X
  50. XThe mail file is only read for the number of messages if the modification
  51. Xtime changes since the last read (saving on disk I/O).  This program also
  52. Xruns with a nice value of 5, and sleeps for 15 seconds between passes.
  53. X(#defined by NICE and SLEEP respectively)
  54. X
  55. XYou might want to place the following lines in your /etc/localprofile
  56. Xor .profile to activate sysinfo apon login:
  57. X
  58. XTTY=`tty`
  59. Xif [ "`expr $TTY : '/dev/w' `" != "0" ]
  60. Xthen 
  61. X    sysinfo
  62. Xfi
  63. X
  64. XPlease report any bugs, suggestions and problems to me:
  65. X
  66. X============================ US MAIL:   Lenny Tropiano, ICUS Computer Group
  67. X IIIII   CCC   U   U   SSSS             PO Box 1
  68. X   I    C   C  U   U  S                 Islip Terrace, New York  11752
  69. X   I    C      U   U   SSS   PHONE:     (516) 968-8576 [H] (516) 582-5525 [W] 
  70. X   I    C   C  U   U      S  AT&T MAIL: ...attmail!icus!lenny  TELEX: 154232428
  71. X IIIII   CCC    UUU   SSSS   UUCP:
  72. X============================    ...{uunet!godfre, harvard!talcott}!\
  73. X                   ...{ihnp4, boulder, mtune, bc-cis, ptsfa, sbcs}! >icus!lenny 
  74. X"Usenet the final frontier"        ...{cmcl2!phri, hoptoad}!dasys1!/
  75. END_OF_README
  76. if test 1842 -ne `wc -c <README`; then
  77.     echo shar: \"README\" unpacked with wrong size!
  78. fi
  79. # end of overwriting check
  80. fi
  81. if test -f Makefile -a "${1}" != "-c" ; then 
  82.   echo shar: Will not over-write existing file \"Makefile\"
  83. else
  84. echo shar: Extracting \"Makefile\" \(474 characters\)
  85. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  86. X#
  87. X# Makefile to compile sysinfo.c  (System Info)
  88. X# By Lenny Tropiano
  89. X# (c)1987 ICUS Computer Group     UUCP:  ...icus!lenny
  90. X#
  91. XCFLAGS=-v -O
  92. XLDFLAGS=-s
  93. XLIBS=/lib/crt0s.o /lib/shlib.ifile
  94. XDEST=/usr/lbin/
  95. X#
  96. Xsysinfo.o:
  97. X    $(CC) $(CFLAGS) -c sysinfo.c
  98. X#
  99. Xsysinfo:  sysinfo.o
  100. X    @echo "Loading ..."
  101. X    $(LD) $(LDFLAGS) $(LIBS) sysinfo.o -o sysinfo
  102. X#
  103. X# You need to be superuser to do this
  104. X#
  105. Xinstall: sysinfo 
  106. X    cp sysinfo $(DEST)
  107. X    chown root $(DEST)
  108. X    chgrp bin  $(DEST)
  109. X    chmod 4750 $(DEST)
  110. END_OF_Makefile
  111. if test 474 -ne `wc -c <Makefile`; then
  112.     echo shar: \"Makefile\" unpacked with wrong size!
  113. fi
  114. # end of overwriting check
  115. fi
  116. if test -f sysinfo.c -a "${1}" != "-c" ; then 
  117.   echo shar: Will not over-write existing file \"sysinfo.c\"
  118. else
  119. echo shar: Extracting \"sysinfo.c\" \(5681 characters\)
  120. sed "s/^X//" >sysinfo.c <<'END_OF_sysinfo'
  121. X/************************************************************************\
  122. X**                                                                      **
  123. X** Program name: sysinfo.c (System Info)                                **
  124. X** Programmer:   Lenny Tropiano            UUCP: ...icus!lenny          **
  125. X** Organization: ICUS Computer Group       (c)1988                      **
  126. X** Date:         January 23, 1988                                       **
  127. X**                                                                      **
  128. X**************************************************************************
  129. X**                                                                      **
  130. X** Credits:      The idea of displaying the file system information     **
  131. X**               came from Scott Hazen Mueller's  newmgr, the replace-  **
  132. X**               ment to the smgr.                                      **
  133. X**                                                                      **
  134. X**************************************************************************
  135. X**                                                                      **
  136. X** Program use:  Program is run as a info process from your .profile    **
  137. X**               This program the file system and displays the          **
  138. X**               pertinent information on the bottom of the screen      **
  139. X**               where the software labels would normally be displayed. **
  140. X**               The program also displays the uptime.                  **
  141. X**                                                                      **
  142. X**************************************************************************
  143. X** Permission is granted to distribute this program by any means as     **
  144. X** long as credit is given for my work.     I would also like to see    **
  145. X** any modifications or enhancements to this program.                   **
  146. X\************************************************************************/
  147. X
  148. X#include <stdio.h>
  149. X#include <fcntl.h>
  150. X#include <errno.h>
  151. X#include <signal.h>
  152. X#include <sys/types.h>
  153. X#include <sys/stat.h>
  154. X#include <sys/window.h>
  155. X#include <sys/filsys.h>
  156. X#include <utmp.h>
  157. X
  158. X#define    MINUTE    60L
  159. X#define    HOUR    (60L * 60L)
  160. X#define    DAY    (24L * 60L * 60L)
  161. X#define    SLEEP    15            /* Sleep time (interval between)*/
  162. X#define    NICE    5            /* Niceness value        */
  163. X                             
  164. X#define LINE_1    "%-40.40s         up  %2d day%1.1s %2d hour%1.1s %2d minute%1.1s"
  165. X#define LINE_2    "Filesystem (%-5.5s) %6ld free  %6ld total blocks  %2d%% available %5d i-nodes"
  166. X#define    FILESYS    "/dev/rfp002"
  167. X#define    FNAME    "fp002"
  168. X#ifndef TRUE
  169. X#define TRUE    1
  170. X#endif
  171. X
  172. Xchar    *progname;            /* program name            */
  173. Xchar    mailfile[30];            /* mailbox file name            */
  174. Xstruct  utdata utd;            /* Window data structure        */
  175. Xstruct  filsys fs;            /* Filesystem superblock struct */
  176. Xtime_t    boottime;            /* system boot time in sec      */
  177. Xtime_t    mailtime = 0L;            /* mail modification time       */
  178. Xint    msgs = 0;
  179. Xunsigned long    days = 0L;
  180. Xunsigned long    hrs  = 0L;
  181. Xunsigned long    mins = 0L;
  182. X
  183. X/************************************************************************/
  184. X
  185. Xmain(argc,argv)
  186. Xint    argc;
  187. Xchar    *argv[];
  188. X{
  189. X    int    terminate();
  190. X    char    *getenv();
  191. X    struct    utmp    *utent, *getutent();
  192. X
  193. X    if (fork() != 0)         /* detach process-info */
  194. X        exit(0);
  195. X        
  196. X    nice(NICE);            /* Be a little nice    */
  197. X    signal (SIGINT, SIG_IGN);
  198. X    signal (SIGQUIT, SIG_IGN);
  199. X     signal (SIGHUP, terminate);
  200. X     signal (SIGTERM, terminate);
  201. X
  202. X        progname = *argv;
  203. X    sprintf(mailfile,"%s",getenv("MAIL"));
  204. X
  205. X    setutent();
  206. X    while ((utent = getutent()) != (struct utmp *)NULL) {
  207. X        if (utent->ut_type == BOOT_TIME) {
  208. X            boottime = utent->ut_time;
  209. X            break;
  210. X        }
  211. X    }
  212. X    endutent();
  213. X
  214. X    info_process();
  215. X    terminate();
  216. X
  217. X}
  218. X
  219. Xinfo_process()
  220. X{
  221. X    char    mailbuffer[40];
  222. X
  223. X    while (TRUE) {
  224. X        filestatus();
  225. X        uptime();
  226. X        mailcheck(mailbuffer);
  227. X
  228. X        utd.ut_num = WTXTSLK1;
  229. X        sprintf(utd.ut_text,LINE_1,
  230. X            mailbuffer,
  231. X            days,(days == 1) ? " " : "s",
  232. X            hrs, (hrs  == 1) ? " " : "s",
  233. X            mins,(mins == 1) ? " " : "s"
  234. X        );
  235. X            ioctl(0, WIOCSETTEXT, &utd);
  236. X
  237. X        utd.ut_num = WTXTSLK2;
  238. X        sprintf(utd.ut_text,LINE_2,
  239. X           FNAME, fs.s_tfree * 2, fs.s_fsize * 2, 
  240. X           (int)((((float)fs.s_tfree / (float)fs.s_fsize) + 0.005) 
  241. X               * 100.0), fs.s_tinode
  242. X        );
  243. X            ioctl(0, WIOCSETTEXT, &utd);
  244. X
  245. X        sleep(SLEEP);
  246. X    }
  247. X}
  248. X
  249. Xint terminate()
  250. X{
  251. X    utd.ut_num = WTXTSLK1;        /* clear the label area */
  252. X    utd.ut_text[0] = '\0';
  253. X        ioctl(0, WIOCSETTEXT, &utd);
  254. X    utd.ut_num = WTXTSLK2;
  255. X        ioctl(0, WIOCSETTEXT, &utd);
  256. X
  257. X    exit(0);
  258. X}
  259. X
  260. Xfilestatus()
  261. X{
  262. X    int    fd;
  263. X
  264. X    if ((fd = open(FILESYS, O_RDONLY)) == -1) {
  265. X        fprintf(stderr,"%s: cannot open %s for read\n",
  266. X            progname, FILESYS);
  267. X        terminate();
  268. X    }
  269. X    
  270. X    if (lseek(fd, 512, 0) == -1) {
  271. X        fprintf(stderr,"%s: cannot lseek to superblock\n", progname);
  272. X        terminate();
  273. X    }
  274. X
  275. X    if (read(fd, &fs, sizeof(struct filsys)) == -1) {
  276. X        fprintf(stderr,"%s: cannot read the superblock\n", progname);
  277. X        terminate();
  278. X    }
  279. X
  280. X    close(fd);
  281. X
  282. X}
  283. X
  284. Xuptime()
  285. X{
  286. X    time_t   curtime, bootsec;
  287. X
  288. X    time(&curtime);
  289. X    bootsec = curtime - boottime;
  290. X
  291. X    days = bootsec / DAY;
  292. X    bootsec -= DAY * days;
  293. X    hrs = bootsec / HOUR;
  294. X    bootsec -= HOUR * hrs;
  295. X    mins = bootsec / MINUTE;
  296. X    bootsec -= MINUTE * mins;
  297. X}
  298. X
  299. Xmailcheck(buf)
  300. Xchar *buf;
  301. X{
  302. X    FILE    *fp;
  303. X    char    buffer[BUFSIZ];
  304. X    struct    stat    statbuf;
  305. X
  306. X    if (access(mailfile,4) == 0) {
  307. X        if (stat(mailfile,&statbuf) != -1) {
  308. X            if (statbuf.st_ctime > mailtime) {
  309. X            msgs = 0;
  310. X            if ((fp = fopen(mailfile,"r")) != NULL) {
  311. X               while (fgets(buffer, BUFSIZ, fp) != NULL) 
  312. X                if (strncmp(buffer,"From ",5) == 0)
  313. X                    msgs++;
  314. X            }
  315. X            fclose(fp);
  316. X            mailtime = statbuf.st_ctime;
  317. X            }
  318. X        }
  319. X    }
  320. X    if (msgs) 
  321. X        sprintf(buf,"%d mail message%s in your mailbox",msgs,
  322. X            (msgs == 1) ? "" : "s");
  323. X    else
  324. X        buf[0] = '\0';
  325. X}
  326. END_OF_sysinfo
  327. fi
  328. if test 5681 -ne `wc -c <sysinfo.c`; then
  329.     echo shar: \"sysinfo.c\" unpacked with wrong size!
  330. fi
  331. # end of overwriting check
  332. echo shar: End of shell archive.
  333. exit 0
  334. -- 
  335. ============================ US MAIL:   Lenny Tropiano, ICUS Computer Group
  336.  IIIII   CCC   U   U   SSSS             PO Box 1
  337.    I    C   C  U   U  S                 Islip Terrace, New York  11752
  338.    I    C      U   U   SSS   PHONE:     (516) 968-8576 [H] (516) 582-5525 [W] 
  339.    I    C   C  U   U      S  AT&T MAIL: ...attmail!icus!lenny  TELEX: 154232428
  340.  IIIII   CCC    UUU   SSSS   UUCP:
  341. ============================    ...{uunet!godfre, harvard!talcott}!\
  342.                    ...{ihnp4, boulder, mtune, bc-cis, ptsfa, sbcs}! >icus!lenny 
  343. "Usenet the final frontier"        ...{cmcl2!phri, hoptoad}!dasys1!/
  344.